using System;

namespace ValidationFramework.Tests
{
	public class Stopwatch
	{
		// Fields
		private long elapsed;
		public static readonly long Frequency;
		private bool isRunning;
		private long startTimeStamp;
		private static readonly double tickFrequency;

		// Methods
		static Stopwatch()
		{
			tickFrequency = 10000000.0;
			tickFrequency /= Frequency;
		}

		public Stopwatch()
		{
			Reset();
		}

		private long GetElapsedDateTimeTicks()
		{
			return GetRawElapsedTicks();
		}

		private long GetRawElapsedTicks()
		{
			var newElapsed = elapsed;
			if (isRunning)
			{
				var num3 = GetTimestamp() - startTimeStamp;
				newElapsed += num3;
			}
			return newElapsed;
		}

		public static long GetTimestamp()
		{
			return DateTime.UtcNow.Ticks;
		}

		public void Reset()
		{
			elapsed = 0L;
			isRunning = false;
			startTimeStamp = 0L;
		}

		public void Start()
		{
			if (!isRunning)
			{
				startTimeStamp = GetTimestamp();
				isRunning = true;
			}
		}

		public static Stopwatch StartNew()
		{
			var stopwatch = new Stopwatch();
			stopwatch.Start();
			return stopwatch;
		}

		public void Stop()
		{
			if (isRunning)
			{
				var num2 = GetTimestamp() - startTimeStamp;
				elapsed += num2;
				isRunning = false;
			}
		}

		// Properties
		public TimeSpan Elapsed
		{
			get
			{
				return new TimeSpan(GetElapsedDateTimeTicks());
			}
		}

		public long ElapsedMilliseconds
		{
			get
			{
				return (GetElapsedDateTimeTicks() / 0x2710L);
			}
		}

		public long ElapsedTicks
		{
			get
			{
				return GetRawElapsedTicks();
			}
		}

		public bool IsRunning
		{
			get
			{
				return isRunning;
			}
		}
	}
}